﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.machines.*;
    import net.wooga.pets.models.world.vos.actors.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class SendToFamilyCommand extends Command {

        public var event:InfoEvent;
        public var world:WorldModel;
        private var _babyVO:BabyVO;

        override public function execute():void{
            this._babyVO = (this.event.info as BabyVO);
            var _local1:String = this.world.getRoomIdsOfType(GameConstants.TYPE_KINDERGARTEN)[0];
            var _local2:IRoom = (this.world.getRoomById(_local1) as IRoom);
            var _local3:KindergartenMachineVO = (_local2.machine as KindergartenMachineVO);
            _local3.removeBaby(this._babyVO);
            var _local4:Object = {taskType:GameConstants.FIND_FAMILY, itemType:GameConstants.ANY_TYPE, onResult:this.onResult};
            var _local5:RequestVO = new RequestVO("send_to_family", {id:this._babyVO.id});
            var _local6:Array = [_local5];
            var _local7:TaskRequestEvent = new TaskRequestEvent(EventConstants.SEND_TASK_REQUEST, _local6, _local4);
            dispatch(_local7);
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:Object;
            var _local3:String;
            if (_arg1.success){
                _local2 = _arg1.data.send_to_family;
                _local3 = this.world.getRoomIdsOfType(GameConstants.TYPE_KINDERGARTEN)[0];
                dispatch(new InfoEvent(EventConstants.CREATE_REWARD_ICONS, _local3, _local2.items));
                dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.HAPPY_FAMILY_POPUP, this._babyVO));
            };
        }

    }
}//package net.wooga.pets.controllers 
